import {
  AuthStateInterface,
  AuthActionTypes,
  LOGIN_TYPE,
  LOGOUT
} from './types'

const initialState: AuthStateInterface = {
  user: '',
  icon: '',
  pages: [],
  history: undefined
}

export function authReducer(
  state = initialState,
  action: AuthActionTypes
): AuthStateInterface {
  switch (action.type) {
    case LOGIN_TYPE:
      return {
        ...state,
        icon: action.value.icon,
        user: action.value.user,
        pages: action.value.pages,
      }
    case LOGOUT:
      return {
        ...state,
        icon: '',
        user: '',
        pages: [],
      }
    default :
      return state
  }
}